-
-
Notifications
You must be signed in to change notification settings - Fork 262
feat(ramps): adds controller methods for region eligibility #7539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ramps): adds controller methods for region eligibility #7539
Conversation
…controller-get-eligibility
…controller-get-eligibility
… into TRAM-2923-ramps-controller-get-eligibility
|
cursor review |
|
cursor review |
|
cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!
| if (action === 'buy') { | ||
| return country.supported; | ||
| } | ||
|
|
||
| if (country.states && country.states.length > 0) { | ||
| const hasSupportedState = country.states.some( | ||
| (state) => state.supported !== false, | ||
| ); | ||
| return country.supported || hasSupportedState; | ||
| } | ||
|
|
||
| return country.supported; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding early return for action buy and not check for the states in line 467-469: I would expect this early return only if no states are there.
why are we early returning the value for buy?
| } | ||
|
|
||
| return country.supported; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCountries filtering ignores action parameter for buy/sell differentiation
Medium Severity
The getCountries method applies the same filtering logic for both 'buy' and 'sell' actions, but according to the PR description, the behavior should differ: for 'buy', filtering should only use country.supported, while for 'sell', it should include countries where country.supported is true OR any state has supported !== false. The current implementation applies the country.supported || hasSupportedState logic regardless of the action parameter. The action variable is passed to the API request but is never used in the filter condition, causing 'buy' to incorrectly include countries that only have supported states but where the country itself is unsupported.
Explanation
Problem:
The RampsController needs to determine whether a user's region is eligible for ramps (on/off-ramp services). This requires fetching eligibility information from the regions API and making it available to consumers.
Solution:
This PR adds region eligibility support to the RampsController:
New
Eligibilitytype - Defines eligibility information returned from/regions/countries/{isoCode}endpoint withaggregator,deposit, andglobalflags indicating what services are available for a region.New
getEligibilityservice method - Calls/regions/countries/{isoCode}to fetch eligibility for a specific region (e.g.,fr,us-ny). The ISO code is normalized to lowercase.Automatic eligibility fetching -
updateGeolocation()now automatically fetches and stores eligibility in controller state after successfully getting geolocation. This ensures eligibility is always up-to-date with the user's current location.New
getCountriescontroller method - Fetches the list of supported countries from/regions/countriesand filters them using OnRampSDK aggregator logic:buy: filters bycountry.supportedsell: filters bycountry.supportedOR if any state hassupported !== falseEligibility in controller state - Eligibility is stored as a persisted property in
RampsControllerState, making it accessible to consumers viacontroller.state.eligibility.Notable implementation details:
fr) and state codes (us-ny)getCountriesuses OnRampSDK's aggregator filtering logic for consistency with existing SDK behaviorReferences
Checklist
Note
Introduces region eligibility support and country listing with caching, and auto-syncs eligibility with geolocation.
eligibilitytoRampsControllerstate (persisted/visible) andupdateEligibility(isoCode)with normalized caching; prevents stale overwrites and clears on failuresupdateGeolocation()now automatically fetches eligibility and retains request caching/TTL semanticsgetCountries(action)to controller with cached responsesRampsService: newgetCountries(regions cache URLs, support filtering),getEligibility(isoCode), shared request helper addingsdk/controller/contextparams; introducesRampsApiService,RAMPS_SDK_VERSION, andcontextoptionresolveJsonModuleto readpackage.jsonversionWritten by Cursor Bugbot for commit 18dd92b. This will update automatically on new commits. Configure here.